package jmm.threadPool.completionService;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class CompletionServiceDemo2 {


    public static void main(String[] args) throws ExecutionException, InterruptedException {

        // 创建线程池
        ExecutorService executor =
                Executors.newFixedThreadPool(3);
        List<Future> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            int finalI = i;
            list.add(executor.submit(()->{
                System.out.println("开始执行");
                return finalI + "执行结束";
            }));
        }

        for (Future future : list) {
            String o = (String) future.get();
            System.out.println(o);
        }
    }
}
